/**
 * Created by yangh on 2016/09/04.
 */
var main = {};
var myScroll;
(function ($) {
    main.init = function () {
        document.addEventListener('touchmove', function (e) {
            e.preventDefault();
        }, false);

        main.initEvent();
    };

    main.initEvent = function() {
        $(".pay-select > div").on("click", function()
        {
            $(".pay-select > div").removeClass("checked");
            $(this).addClass("checked");
        })
    };

    // /**
    //  * @func move()
    //  * @desc 监听滚动条的位置，异步加载列表
    //  */
    function move() {
        

        if (myScroll.y < main.max - 50) {
            var maxid=$("#produceList li:last").val();
            console.log(maxid);
        
        	 $.ajax({
         		type:"post",
         		async:true, 
 	        	url:path+"/cheapGoogs/more?maxId="+maxid,
         		success:function(resultjson){	
         			if('000' == resultjson.code){
         				var html = "";
         				for (var i = 0; i < resultjson.result.length; i++) {
         				      html += '<li value="'+resultjson.result[i].id+'"><a href="${path}/commodity/info?goodsId='+resultjson.result[i].id+'"><div class="imgBox"><img src="'+resultjson.result[i].picurl+'" alt=""></div><h3>'+resultjson.result[i].name+'</h3><div class="originPrice">原价:￥'+resultjson.result[i].price+'元</div><p>特价:'+resultjson.result[i].promotionPrice+'元</p></a><button onclick="buy('+resultjson.result[i].id+')">立即购买</button></li>';
         			         
         				}	
         				$("#produceList").append(html);
         			}
         		}
         	})
        	
            
            
            
            myScroll.refresh();
            main.max = myScroll.maxScrollY;
            //canLoad = true;
            console.log(main.max);
        }
    }

    /**
     * @func main.scroll()
     * @desc 配置iscroll插件
     */
    main.scroll = function () {
        myScroll = new IScroll(".content", {
            probeType: 3,
            mouseWheel: true,
            click: true,
            preventDefault: false
        });

        main.max = myScroll.maxScrollY;
        console.log(main.max);

        myScroll.on("scroll", move);
    };
})(jQuery);

main.init();

window.onload = function () {
    main.scroll();
};